package workspace.teaweb.CRM.controllers;


import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import workspace.teaweb.CRM.pojo.dto.CrmQuery;
import workspace.teaweb.CRM.pojo.entity.CRM;
import workspace.teaweb.CRM.pojo.vo.CRMVO;
import workspace.teaweb.CRM.service.CRMService;
import workspace.teaweb.base.response.JsonResult;

import java.util.List;

@Validated//验证
@Slf4j
@Api(tags = "员工管理")
@RestController
@RequestMapping("/crm")
public class CRMController {

    @Autowired
    CRMService crmService; // 使用接口1

    // 增加员工记录
    @PostMapping("/add")
    public JsonResult addCRM(@RequestBody CRM crm) {
        crmService.addCRM(crm);
        return JsonResult.ok();
    }

    // 删除员工记录
    @DeleteMapping("/delete/{id}")
    public JsonResult deleteCRM(@PathVariable int id) {
        crmService.deleteCRM(id);
        return JsonResult.ok();
    }

    // 更新员工记录
    @PutMapping("/update")
    public JsonResult updateCRM(@RequestBody CRM crm) {
        crmService.updateCRM(crm);
        return JsonResult.ok();
    }

    // 获取所有员工记录
    @GetMapping("/all")
    public JsonResult getAllCRM() {
        List<CRM> list=crmService.getAllCRM();
        return JsonResult.ok(list);
    }


    // 记录加班小时
    @PostMapping("/recordOverHour")
    public JsonResult recordOverHour(@RequestParam int id, @RequestParam int hours) {
        crmService.recordOverHour(id, hours);
        return JsonResult.ok();
    }

    // 记录请假小时
    @PostMapping("/recordLeaveHour")
    public JsonResult recordLeaveHour(@RequestParam int id, @RequestParam int hours) {
        crmService.recordLeaveHour(id, hours);
        return JsonResult.ok();
    }
    //查询员工
    @GetMapping("/select")
    public JsonResult selevtCRM(@RequestBody CrmQuery crmQuery) {
        List<CRMVO> list = crmService.selectCRM(crmQuery);
        return JsonResult.ok(list);
    }

}











